package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Integral;
import cn.wolfcode.trip.base.domain.IntegralType;
import cn.wolfcode.trip.base.mapper.IntegralTypeMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IIntegralTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：积分类型业务层实现类
 *
 * @package: cn.wolfcode.trip.base.service.impl
 * @author: Patch
 * @date: 2019/5/30 13:19
 * 总结:
 */
@Service
public class IntegralTypeServiceImpl implements IIntegralTypeService {
    @Autowired
    private IntegralTypeMapper typeMapper;

    @Override
    public void saveOrUpdate(IntegralType type) {
        // 设置创建时间
        type.setInputTime(new Date());
        if (type.getId() != null) {
            typeMapper.updateByPrimaryKey(type);
        } else {
            typeMapper.insert(type);
        }
    }

    @Override
    public PageInfo<IntegralType> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), qo.getOrderBy());
        List<IntegralType> list = typeMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public List<IntegralType> listAll() {
        return typeMapper.selectAll();
    }

    @Override
    public Integer selectGradeById(Long id) {
        return typeMapper.selectGradeById(id);
    }

    @Override
    public void updateGrade(Long typeId, int grade) {
        typeMapper.updateGrade(typeId,grade);
    }



}
